package com.ruoyi.web.controller.shortplay;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shortplay.domain.MyChannelVideo;
import com.ruoyi.shortplay.domain.SupportedLanguagesIO;
import com.ruoyi.shortplay.service.IMyChannelVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 我频道下的视频Controller
 *
 * @author ruoyi
 * @date 2025-11-18
 */
@RestController
@RequestMapping("/shortplay/channelvideo")
public class MyChannelVideoController extends BaseController {

    @Autowired
    private IMyChannelVideoService myChannelVideoService;

    /**
     * 查询我频道下的视频列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MyChannelVideo myChannelVideo) {
        startPage();
        List<MyChannelVideo> list = myChannelVideoService.selectMyChannelVideoList(myChannelVideo);
        return getDataTable(list);
    }

    /**
     * 导出我频道下的视频列表
     */
    @Log(title = "我频道下的视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyChannelVideo myChannelVideo)    {
        List<MyChannelVideo> list = myChannelVideoService.selectMyChannelVideoList(myChannelVideo);
        ExcelUtil<MyChannelVideo> util = new ExcelUtil<MyChannelVideo>(MyChannelVideo.class);
        util.exportExcel(response, list, "我频道下的视频数据");
    }

    /**
     * 获取我频道下的视频详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)    {
        return success(myChannelVideoService.selectMyChannelVideoById(id));
    }

    /**
     * 新增我频道下的视频
     */
    @Log(title = "我频道下的视频", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyChannelVideo myChannelVideo)    {
        return toAjax(myChannelVideoService.insertMyChannelVideo(myChannelVideo));
    }

    /**
     * 修改我频道下的视频
     */
    @Log(title = "我频道下的视频", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyChannelVideo myChannelVideo)    {
        return myChannelVideoService.updateMyChannelVideo(myChannelVideo);
    }

    /**
     * 更新按钮：根据视频id 同步youtobe信息，更新封面，标题，播放量第二个信息
     */
    @Log(title = "我频道下的视频", businessType = BusinessType.UPDATE)
    @PutMapping("updateByVideoId")
    public AjaxResult updateByYoutobeData(@RequestBody MyChannelVideo myChannelVideo)    {
        return myChannelVideoService.updateByYoutobeData(myChannelVideo);
    }


    /**
     * 删除我频道下的视频
     */
    @Log(title = "我频道下的视频", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)    {
        return toAjax(myChannelVideoService.deleteMyChannelVideoByIds(ids));
    }

    /**
     * 新增我频道下的视频
     */
    @Log(title = "添加多语言标题")
    @PostMapping("addSupportedLanguages")
    public AjaxResult addSupportedLanguages(@RequestBody SupportedLanguagesIO params)    {
        return myChannelVideoService.addSupportedLanguages(params);
    }

    /**
     * 新增我频道下的视频
     */
    @Log(title = "翻译")
    @PostMapping("titleTranslation")
    public AjaxResult titleTranslation(@RequestBody SupportedLanguagesIO params)    {
        return myChannelVideoService.titleTranslation(params);
    }

    @Log(title = "翻译")
    @PostMapping("titleTranslationTwo")
    public AjaxResult titleTranslationTwo(@RequestBody SupportedLanguagesIO params)    {
        return myChannelVideoService.titleTranslationTwo(params);
    }
}
